Skip to content

feat: review queue and PR fixer workflows - #63

Merged
Gkrumbach07 merged 2 commits into
mainfrom
worktree-review-queue
Mar 10, 2026
Merged

Gkrumbach07 merged 2 commits into
mainfrom
worktree-review-queue

Conversation

@Gkrumbach07

Copy link
Copy Markdown
Collaborator

Summary

  • Review Queue: transforms pr-overview from a merge meeting doc generator into a prioritized review queue — ordered by PR type (bugs first), urgency, and size
  • PR Fixer: new workflow that fixes individual PRs — rebases, addresses reviewer feedback, runs lints/tests, posts fix report as PR comment

Review Queue changes

  • PR type classification (bug-fix, feature, refactor, chore, docs) via unified TYPE_SIGNALS
  • Sub-agents read ALL comments as a unified chronological stream (no bot vs human parsing)
  • Removed merge order testing — not needed for a review queue
  • Milestone renamed to "Review Queue" (backward compat with "Merge Queue")
  • Fix: UNKNOWN mergeability returns warn not FAIL
  • Fix: empty-body reviews filtered from comment stream
  • Fix: eliminated double-read via pr_data_cache
  • Fix: TOCTOU replaced with try/except

PR Fixer

  • fetch-pr.sh with parallel API calls
  • merge-comments.py for unified comment stream (shared logic with analyze-prs.py)
  • Agent rebases, evaluates comments, fixes valid issues, responds to invalid ones
  • Fix report posted as PR comment with <!-- pr-fixer-bot --> marker

Test plan

  • Run review queue workflow against a repo with open PRs
  • Run PR fixer against a PR with merge conflicts
  • Run PR fixer against a PR with reviewer feedback
  • Verify analyze-prs.py type classification on PRs with various labels/branches
  • Verify milestone management creates/syncs "Review Queue" milestone

🤖 Generated with Claude Code

Review Queue (internal-workflows/pr-overview):
- Reframe from "merge meeting" to prioritized review queue
- Add PR type classification (bug-fix, feature, refactor, chore, docs)
  via unified TYPE_SIGNALS data structure
- Sub-agents now read ALL comments as a unified chronological stream
  instead of parsing bot vs human separately
- Ranking prioritizes by type (bugs first), then blockers, then size
- Remove merge order testing (test-merge-order.sh) — not needed for review
- Milestone renamed to "Review Queue" (backward compat with "Merge Queue")
- Blocker comments use <!-- review-queue-bot --> marker
- Fix: UNKNOWN mergeability returns warn instead of FAIL
- Fix: filter empty-body reviews from comment stream
- Fix: eliminate double-read of PR JSON via pr_data_cache
- Fix: TOCTOU — use try/except instead of os.path.exists

PR Fixer (internal-workflows/pr-fixer):
- New workflow to fix individual PRs
- fetch-pr.sh: parallel API calls, unified comment stream via merge-comments.py
- Agent rebases, evaluates reviewer comments (fix valid, respond to invalid),
  runs lints/tests, pushes with --force-with-lease
- Fix report posted as PR comment (<!-- pr-fixer-bot --> marker)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Gkrumbach07
Gkrumbach07 marked this pull request as ready for review March 10, 2026 18:06
@coderabbitai

coderabbitai Bot commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@Gkrumbach07 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 59 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e20ed3cf-cfc6-429c-a61b-7b48cc80a5fc

📥 Commits

Reviewing files that changed from the base of the PR and between cf1cd1f and 200e55f.

📒 Files selected for processing (7)
  • internal-workflows/pr-fixer/README.md
  • internal-workflows/pr-fixer/scripts/fetch-pr.sh
  • internal-workflows/pr-overview/.ambient/ambient.json
  • internal-workflows/pr-overview/.ambient/rubric.md
  • internal-workflows/pr-overview/CLAUDE.md
  • internal-workflows/pr-overview/README.md
  • internal-workflows/pr-overview/scripts/analyze-prs.py

Walkthrough

The changes introduce a new PR Fixer workflow for automated PR fixes and significantly refactor the PR Overview workflow into a Review Queue system with PR type classification and sub-agent evaluation. New configuration, documentation, and scripts are added for PR Fixer; the Review Queue workflow is renamed, restructured across multiple phases, and includes updated analysis logic and output templates.

Changes

Cohort / File(s) Summary
PR Fixer Configuration & Documentation
internal-workflows/pr-fixer/.ambient/ambient.json, internal-workflows/pr-fixer/CLAUDE.md, internal-workflows/pr-fixer/README.md
New PR Fixer workflow configuration declaring an agent to fix single PRs via rebasing and test cycles; comprehensive agent instructions for fetch, rebase, review feedback, lint/test, and push phases; documentation of prerequisites, quick start, and directory structure.
PR Fixer Data Pipeline
internal-workflows/pr-fixer/scripts/fetch-pr.sh, internal-workflows/pr-fixer/scripts/merge-comments.py
New Bash script to fetch and aggregate PR metadata, reviews, comments, diffs, and CI status into structured JSON artifacts; new Python script to merge PR comments, formal reviews, and inline comments into a single chronologically sorted array.
Review Queue Workflow Configuration
internal-workflows/pr-overview/.ambient/ambient.json, internal-workflows/pr-overview/.ambient/rubric.md
Renamed workflow from "PR Overview" to "Review Queue"; updated system prompts to emphasize attention-ordered queue generation; restructured 8-step to 10-step checklist; replaced artifact names (merge-meeting to review-queue); revised execution efficiency rubric with updated criteria and expected tool-call range (~13–18).
Review Queue Workflow Instructions & Documentation
internal-workflows/pr-overview/CLAUDE.md, internal-workflows/pr-overview/README.md
Renamed and substantially restructured agent instructions; shifted phases from merge-readiness to review-readiness; added PR type classification (bug-fix, feature, refactor, chore, docs, unknown); introduced sub-agent evaluation per PR batch; replaced merge-order with review-order logic; updated milestone terminology and comment markers; rewrote README to describe queue generation, type classification, and readiness criteria.
Review Queue Analysis & Output
internal-workflows/pr-overview/scripts/analyze-prs.py, internal-workflows/pr-overview/templates/review-queue.md
Added PR type classification function, type signals, and priority constants; introduced unified comment merging and per-PR review extraction; renamed compute\_merge\_order to compute\_review\_order; added pr\_type field to PR data model; new Handlebars-style review queue template with sections for ready PRs, blockers, and close recommendations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FetchScript as fetch-pr.sh
    participant GitHub as GitHub API
    participant MergeComments as merge-comments.py
    participant PRFixerAgent as PR Fixer Agent

    User->>FetchScript: Call with --repo and --pr
    FetchScript->>FetchScript: Validate inputs & auth
    FetchScript->>GitHub: Fetch PR metadata
    GitHub-->>FetchScript: pr.json
    FetchScript->>GitHub: Fetch reviews & comments (parallel)
    GitHub-->>FetchScript: reviews.json, review_comments.json
    FetchScript->>GitHub: Fetch PR diff & CI status
    GitHub-->>FetchScript: diff.json, ci.json
    FetchScript->>MergeComments: Invoke with comment files
    MergeComments->>MergeComments: Load & normalize sources
    MergeComments->>MergeComments: Sort chronologically
    MergeComments-->>FetchScript: comments.json (unified)
    FetchScript-->>User: artifacts/ summary
    User->>PRFixerAgent: Invoke with artifact path
    PRFixerAgent->>PRFixerAgent: Rebase, review, test, push
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the two main features introduced: a review queue workflow and a PR fixer workflow. It is concise and clearly conveys the primary changes.
Description check ✅ Passed The description is directly related to the changeset, detailing the review queue transformation, PR fixer workflow, specific changes, and test plan. It clearly explains the purpose and scope of modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch worktree-review-queue

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 12

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal-workflows/pr-overview/CLAUDE.md (1)

148-150: ⚠️ Potential issue | 🟠 Major

Align the mergeability rule with analyze-prs.py.

The script now reports mergeable == "UNKNOWN" as warn, but this instruction still tells the agent to treat it as a blocker. That mismatch will make milestone sync and blocker comments disagree with analysis.json.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal-workflows/pr-overview/CLAUDE.md` around lines 148 - 150, The
mergeability guidance currently treats `mergeable == "UNKNOWN"` as a blocker,
which conflicts with `analyze-prs.py` and `analysis.json`; update the text so
that `UNKNOWN` is treated as a warning (not a blocker) and only `CONFLICTING` is
a blocker, and adjust the bullets mentioning `MERGEABLE`/`CONFLICTING`/`UNKNOWN`
(and any guidance about noting overlapping files) to reflect this behavior;
reference `mergeable`, `MERGEABLE`, `CONFLICTING`, `UNKNOWN`, and
`analyze-prs.py` when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal-workflows/pr-fixer/.ambient/ambient.json`:
- Around line 1-7: Update the ambient.json so the systemPrompt explicitly
documents the artifact output path and the results field uses the same path: in
the object with "name": "PR Fixer" update the "systemPrompt" string to include
the artifact path pattern (e.g., "artifacts/pr-fixer/{number}/" or
"artifacts/pr-fixer/") for generated outputs and then add/adjust the "results"
field to reference that same artifact path (keeping "systemPrompt",
"startupPrompt" and "results" keys intact so consumers can find artifacts
consistently).

In `@internal-workflows/pr-fixer/CLAUDE.md`:
- Around line 5-13: Change the incorrect h3 heading back to h2 to restore proper
Markdown hierarchy: locate the "Prerequisites" section heading in CLAUDE.md
(currently using ###) and replace it with ## so it follows the top-level title
correctly and satisfies MD001.

In `@internal-workflows/pr-fixer/README.md`:
- Around line 25-35: Update the fenced code block in README.md that displays the
pr-fixer/ directory tree to include a language specifier (e.g., change the
opening ``` to ```text or ```plaintext) so it satisfies MD040; locate the block
showing "pr-fixer/" and the nested entries (including .ambient/, CLAUDE.md,
scripts/, artifacts/) and only modify the opening fence to add the specifier.

In `@internal-workflows/pr-fixer/scripts/fetch-pr.sh`:
- Around line 81-103: The gh calls (gh pr view and the three gh api lines)
currently discard stderr with 2>/dev/null which hides API errors; change each
command to redirect stderr into a per-request temp error file in TMPDIR (e.g.
pr.err, reviews.err, review_comments.err, diff.err) instead of /dev/null, keep
the background PIDs (PID_PR, PID_REVIEWS, PID_RC, PID_DIFF) as-is, and update
the wait/fallback block to, on failure, echo or cat the corresponding temp error
file to stderr (and still write the existing fallback JSON into
OUTPUT_DIR/TMPDIR as needed) so failures are preserved for debugging while
retaining the existing fallback behavior.
- Around line 105-114: Add headRefOid to DETAIL_FIELDS and use it to set
HEAD_SHA instead of digging into statusCheckRollup: update the DETAIL_FIELDS
constant (referenced around line 77) to include "headRefOid", then replace the
current jq extraction that sets HEAD_SHA from .statusCheckRollup[...] with a
simple read of .headRefOid from "${OUTPUT_DIR}/pr.json" (the variable HEAD_SHA
and the script block that writes to "${OUTPUT_DIR}/ci.json" should remain
unchanged); ensure the new jq usage falls back to empty on missing values and
preserves the existing error suppression/|| true behavior.

In `@internal-workflows/pr-overview/.ambient/ambient.json`:
- Around line 4-5: The ambient prompts (keys systemPrompt and startupPrompt in
ambient.json) are stale: remove the obsolete "test merge order" instruction,
update the checklist reference from "10-step" to "9-step", and bring the
systemPrompt into the required contract by explicitly including a role
definition, a list of available commands with short purposes, the updated
workflow phases, output locations, and a workspace navigation block that gives
file location guidelines; also update startupPrompt to reference the 9-step
checklist and include command/phase/output/workspace-navigation expectations so
the Review Queue agent executes the correct workflow.

In `@internal-workflows/pr-overview/.ambient/rubric.md`:
- Around line 45-54: The benchmark step order is incorrect: update the numbered
list in the "Benchmark" section so that "Read analysis summary + needed per-PR
files" happens during the per-PR evaluation step (move the current step 6 into
step 4 alongside "Spawn parallel sub-agents for per-PR evaluation") to match
CLAUDE.md Phase 3; renumber the subsequent steps (original steps 4–8 → 5–9
accordingly) and adjust the Total call estimate to reflect the reordered
sequence so tool-call economy aligns with the actual workflow.

In `@internal-workflows/pr-overview/CLAUDE.md`:
- Around line 99-116: analyze-prs.py currently emits only transient outputs; add
a persisted, schemaed artifact that serializes each sub-agent's verdict (fields:
number, verdict, review_summary, action_needed, action_owner,
blockers_from_comments) so downstream report/comment steps can reliably consume
it; implement this in analyze-prs.py by assembling a list/object per PR,
validate required fields, write atomically to a single JSON (or NDJSON) artifact
in the workflow workspace, and update the report/comment consumers to
read/validate that artifact instead of relying on in-memory data; ensure the
artifact format is stable and include simple validation/error messages when
required fields are missing.

In `@internal-workflows/pr-overview/README.md`:
- Around line 24-40: The fenced code block showing the directory tree (the block
that begins with the line "pr-overview/") is missing a language specifier,
triggering MD040; update the opening fence from ``` to a language-specific fence
such as ```text to satisfy the linter. Ensure the same change is applied to the
README.md code block that contains the "pr-overview/" directory listing so the
block starts with ```text.

In `@internal-workflows/pr-overview/scripts/analyze-prs.py`:
- Around line 560-564: fail_count is computed from [ci_status, conflict_status,
review_status, stale_status] before overlap_status is determined, so PRs later
marked FAIL for diff-overlap aren’t counted as blocked; update the logic so
fail_count includes overlap_status by either computing overlap_status before
building the list used in fail_count or recomputing fail_count after
overlap_status is set (reference the fail_count variable and the overlap_status
variable in analyze-prs.py), ensuring the list passed to sum(...) contains
overlap_status when determining blocker counts used for ranking and
review_order.
- Around line 190-197: The function check_reviews currently returns
"needs_review" when fetch_ok is False which lets unreadable PR payloads be
treated as clean; change the early return in check_reviews (the fetch_ok guard)
to return a failing status (e.g., "FAIL") instead of "needs_review" so the PR is
treated as a blocker—keep the same detail string ("PR data incomplete — fetch
may have failed") and has_comments flag (True) so callers can immediately mark
the PR as failed/sync-blocking.

In `@internal-workflows/pr-overview/templates/review-queue.md`:
- Around line 66-73: Insert the hidden HTML marker <!-- review-queue-bot -->
into the review-queue template so generated reports are identifiable by the
workflow; add this marker as a standalone HTML comment at the top (or bottom) of
the template content (outside the Markdown headings) while leaving the existing
variables like {{READY_COUNT}}, {{MILESTONE_COUNT}}, {{NEAR_COUNT}},
{{WORK_COUNT}}, {{CLOSE_COUNT}}, and optional {{FORK_COUNT}} unchanged.

---

Outside diff comments:
In `@internal-workflows/pr-overview/CLAUDE.md`:
- Around line 148-150: The mergeability guidance currently treats `mergeable ==
"UNKNOWN"` as a blocker, which conflicts with `analyze-prs.py` and
`analysis.json`; update the text so that `UNKNOWN` is treated as a warning (not
a blocker) and only `CONFLICTING` is a blocker, and adjust the bullets
mentioning `MERGEABLE`/`CONFLICTING`/`UNKNOWN` (and any guidance about noting
overlapping files) to reflect this behavior; reference `mergeable`, `MERGEABLE`,
`CONFLICTING`, `UNKNOWN`, and `analyze-prs.py` when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5c0c1733-fc2b-4d4f-a428-db177917fa5a

📥 Commits

Reviewing files that changed from the base of the PR and between c45ee1d and cf1cd1f.

📒 Files selected for processing (11)
  • internal-workflows/pr-fixer/.ambient/ambient.json
  • internal-workflows/pr-fixer/CLAUDE.md
  • internal-workflows/pr-fixer/README.md
  • internal-workflows/pr-fixer/scripts/fetch-pr.sh
  • internal-workflows/pr-fixer/scripts/merge-comments.py
  • internal-workflows/pr-overview/.ambient/ambient.json
  • internal-workflows/pr-overview/.ambient/rubric.md
  • internal-workflows/pr-overview/CLAUDE.md
  • internal-workflows/pr-overview/README.md
  • internal-workflows/pr-overview/scripts/analyze-prs.py
  • internal-workflows/pr-overview/templates/review-queue.md

Comment on lines +1 to +7
{
"name": "PR Fixer",
"description": "Fix a single PR: rebase to resolve conflicts, address reviewer feedback, run lints and tests, and push clean commits",
"systemPrompt": "You are a PR fixer agent. Follow the instructions in CLAUDE.md to fix a single pull request: fetch its data, rebase to resolve conflicts, evaluate and address reviewer comments, run lints and tests, and push the fixes. You operate on one PR at a time.",
"startupPrompt": "You are the PR Fixer agent. Follow the instructions in CLAUDE.md. Ask for the repo and PR number if not provided, then start the fix process.",
"results": {}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider specifying artifact paths in systemPrompt and results.

Per coding guidelines, the systemPrompt output section should specify artifact paths as artifacts/{workflow-name}/, and these paths should be consistent with the results field. The CLAUDE.md references artifacts/pr-fixer/{number}/ but neither the systemPrompt nor results field documents this.

📝 Proposed enhancement
 {
   "name": "PR Fixer",
   "description": "Fix a single PR: rebase to resolve conflicts, address reviewer feedback, run lints and tests, and push clean commits",
-  "systemPrompt": "You are a PR fixer agent. Follow the instructions in CLAUDE.md to fix a single pull request: fetch its data, rebase to resolve conflicts, evaluate and address reviewer comments, run lints and tests, and push the fixes. You operate on one PR at a time.",
+  "systemPrompt": "You are a PR fixer agent. Follow the instructions in CLAUDE.md to fix a single pull request: fetch its data, rebase to resolve conflicts, evaluate and address reviewer comments, run lints and tests, and push the fixes. You operate on one PR at a time. Output artifacts to artifacts/pr-fixer/{number}/.",
   "startupPrompt": "You are the PR Fixer agent. Follow the instructions in CLAUDE.md. Ask for the repo and PR number if not provided, then start the fix process.",
-  "results": {}
+  "results": {
+    "pr_data": "artifacts/pr-fixer/{number}/pr.json",
+    "comments": "artifacts/pr-fixer/{number}/comments.json",
+    "diff": "artifacts/pr-fixer/{number}/diff.json",
+    "ci": "artifacts/pr-fixer/{number}/ci.json"
+  }
 }

As per coding guidelines: "The systemPrompt output section must specify artifact paths as artifacts/{workflow-name}/ and these paths must be consistent with the results field in ambient.json"

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal-workflows/pr-fixer/.ambient/ambient.json` around lines 1 - 7, Update
the ambient.json so the systemPrompt explicitly documents the artifact output
path and the results field uses the same path: in the object with "name": "PR
Fixer" update the "systemPrompt" string to include the artifact path pattern
(e.g., "artifacts/pr-fixer/{number}/" or "artifacts/pr-fixer/") for generated
outputs and then add/adjust the "results" field to reference that same artifact
path (keeping "systemPrompt", "startupPrompt" and "results" keys intact so
consumers can find artifacts consistently).

Comment on lines +5 to +13
## Prerequisites

You need:

- **Repo**: `owner/repo` (e.g., `ambient-code/platform`)
- **PR number**: the PR to fix
- **Repo clone**: the repo must be cloned locally (you'll work in a branch)

If these aren't provided, ask for them before starting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Fix heading level increment.

The heading jumps from h1 (#) directly to h3 (###), violating Markdown heading hierarchy (MD001). Change to h2 for consistency.

📝 Proposed fix
-### Prerequisites
+## Prerequisites

 You need:
🧰 Tools
🪛 markdownlint-cli2 (0.21.0)

[warning] 6-6: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal-workflows/pr-fixer/CLAUDE.md` around lines 5 - 13, Change the
incorrect h3 heading back to h2 to restore proper Markdown hierarchy: locate the
"Prerequisites" section heading in CLAUDE.md (currently using ###) and replace
it with ## so it follows the top-level title correctly and satisfies MD001.

Comment thread internal-workflows/pr-fixer/README.md Resolved
Comment on lines +81 to +103
gh pr view "$PR_NUM" --repo "$REPO" --json "$DETAIL_FIELDS" \
2>/dev/null > "${OUTPUT_DIR}/pr.json" &
PID_PR=$!

gh api "repos/${OWNER}/${REPO_NAME}/pulls/${PR_NUM}/reviews" \
--paginate 2>/dev/null > "${TMPDIR}/reviews.json" &
PID_REVIEWS=$!

gh api "repos/${OWNER}/${REPO_NAME}/pulls/${PR_NUM}/comments" \
--paginate 2>/dev/null > "${TMPDIR}/review_comments.json" &
PID_RC=$!

gh api "repos/${OWNER}/${REPO_NAME}/pulls/${PR_NUM}/files" \
--paginate 2>/dev/null \
| jq '[.[] | {filename, status, additions, deletions, patch}]' \
> "${OUTPUT_DIR}/diff.json" &
PID_DIFF=$!

# Wait for all parallel fetches, handling failures
wait "$PID_PR" 2>/dev/null || echo '{}' > "${OUTPUT_DIR}/pr.json"
wait "$PID_REVIEWS" 2>/dev/null || echo '[]' > "${TMPDIR}/reviews.json"
wait "$PID_RC" 2>/dev/null || echo '[]' > "${TMPDIR}/review_comments.json"
wait "$PID_DIFF" 2>/dev/null || echo '[]' > "${OUTPUT_DIR}/diff.json"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider preserving API errors for debugging.

The stderr redirection (2>/dev/null) on the gh commands hides API errors, which could make it difficult to diagnose why a fetch failed. The fallback logic correctly handles failures, but users won't know why it failed.

💡 Suggested approach

Consider logging errors to a temp file and displaying them on failure:

 gh pr view "$PR_NUM" --repo "$REPO" --json "$DETAIL_FIELDS" \
-    2>/dev/null > "${OUTPUT_DIR}/pr.json" &
+    > "${OUTPUT_DIR}/pr.json" 2>"${TMPDIR}/pr_err.log" &
 PID_PR=$!

Then in the wait section:

-wait "$PID_PR" 2>/dev/null || echo '{}' > "${OUTPUT_DIR}/pr.json"
+wait "$PID_PR" 2>/dev/null || { cat "${TMPDIR}/pr_err.log" >&2; echo '{}' > "${OUTPUT_DIR}/pr.json"; }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal-workflows/pr-fixer/scripts/fetch-pr.sh` around lines 81 - 103, The
gh calls (gh pr view and the three gh api lines) currently discard stderr with
2>/dev/null which hides API errors; change each command to redirect stderr into
a per-request temp error file in TMPDIR (e.g. pr.err, reviews.err,
review_comments.err, diff.err) instead of /dev/null, keep the background PIDs
(PID_PR, PID_REVIEWS, PID_RC, PID_DIFF) as-is, and update the wait/fallback
block to, on failure, echo or cat the corresponding temp error file to stderr
(and still write the existing fallback JSON into OUTPUT_DIR/TMPDIR as needed) so
failures are preserved for debugging while retaining the existing fallback
behavior.

Comment on lines +99 to +116
> For each PR, return a verdict with these fields:
> - **number**: PR number
> - **verdict**: `ready` (no blockers, needs human approval), `almost` (1 minor issue), `blocked` (real blockers), `stale` (abandoned/inactive)
> - **review_summary**: 1-2 sentences capturing the review state — who reviewed, what was raised, whether it was addressed. Be specific.
> - **action_needed**: What a human should do next (e.g., "Approve — all feedback addressed", "Author needs to fix CI", "Reviewer @alice has unresolved concern about error handling")
> - **action_owner**: Who needs to act — `@author`, `@reviewer`, `@maintainer`, or a specific username
> - **blockers_from_comments**: List of genuine blockers found in comments (empty list if none). Only real issues — not style nits, not stale bot findings on old commits.
>
> For each PR, return: PR number, verdict (FAIL or pass), and a 1-2 sentence explanation of your reasoning. For FAIL, describe the specific issue. For pass, briefly note what was found and why it's not blocking (e.g., "Major: naming suggestion — style only, not blocking").
> Key judgment calls:
> - A bot review from 3 weeks ago on a different commit is probably stale — note it but don't block on it
> - A human requesting changes, author pushing a fix, but no re-approval = needs reviewer to re-review, not a blocker from comments
> - "nit" comments or style suggestions with CHANGES_REQUESTED state = not a real blocker, note the mismatch
> - Multiple rounds of review with all issues addressed = ready for approval
> - Unresolved substantive disagreement = blocked, explain the disagreement
>
> PRs to evaluate: {batch list}

Each comment is a small file — no truncation, no size limits. The sub-agent reads newest first and stops early once it has a verdict.
Collect all verdicts from the parallel sub-agents and update each PR's review data before proceeding.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Define a persisted artifact for sub-agent verdicts.

This section introduces verdict, review_summary, action_needed, action_owner, and blockers_from_comments, but it never specifies where those fields are written. In the current implementation, internal-workflows/pr-overview/scripts/analyze-prs.py only emits mechanical per-PR analysis plus raw comment files, so later phases have no stable artifact to read unless everything stays in memory. Please define an explicit file/schema for sub-agent outputs before the report and comment steps depend on them.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal-workflows/pr-overview/CLAUDE.md` around lines 99 - 116,
analyze-prs.py currently emits only transient outputs; add a persisted, schemaed
artifact that serializes each sub-agent's verdict (fields: number, verdict,
review_summary, action_needed, action_owner, blockers_from_comments) so
downstream report/comment steps can reliably consume it; implement this in
analyze-prs.py by assembling a list/object per PR, validate required fields,
write atomically to a single JSON (or NDJSON) artifact in the workflow
workspace, and update the report/comment consumers to read/validate that
artifact instead of relying on in-memory data; ensure the artifact format is
stable and include simple validation/error messages when required fields are
missing.

Comment on lines +66 to +73
## Summary

- **Ready for review:** {{READY_COUNT}} PRs with zero blockers
- **In Review Queue:** {{MILESTONE_COUNT}} PRs
- **One blocker away:** {{NEAR_COUNT}} PRs
- **Needs work:** {{WORK_COUNT}} PRs
- **Recommend closing:** {{CLOSE_COUNT}} PRs
{{#if FORK_COUNT}}- **Fork PRs:** {{FORK_COUNT}} (marked in tables — no automated agent review, require manual review){{/if}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider adding the workflow identification marker.

Per retrieved learnings, workflow-generated reports should include the <!-- review-queue-bot --> HTML marker for identification (the PR description mentions using this marker for blocker comments). Adding it to the template ensures consistency.

📝 Proposed addition at end of template
 - **Recommend closing:** {{CLOSE_COUNT}} PRs
 {{`#if` FORK_COUNT}}- **Fork PRs:** {{FORK_COUNT}} (marked in tables — no automated agent review, require manual review){{/if}}
+
+<!-- review-queue-bot -->

Based on learnings: "use hidden HTML marker '' to identify workflow-generated comments" (the PR renames this to <!-- review-queue-bot -->).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Summary
- **Ready for review:** {{READY_COUNT}} PRs with zero blockers
- **In Review Queue:** {{MILESTONE_COUNT}} PRs
- **One blocker away:** {{NEAR_COUNT}} PRs
- **Needs work:** {{WORK_COUNT}} PRs
- **Recommend closing:** {{CLOSE_COUNT}} PRs
{{#if FORK_COUNT}}- **Fork PRs:** {{FORK_COUNT}} (marked in tables — no automated agent review, require manual review){{/if}}
## Summary
- **Ready for review:** {{READY_COUNT}} PRs with zero blockers
- **In Review Queue:** {{MILESTONE_COUNT}} PRs
- **One blocker away:** {{NEAR_COUNT}} PRs
- **Needs work:** {{WORK_COUNT}} PRs
- **Recommend closing:** {{CLOSE_COUNT}} PRs
{{`#if` FORK_COUNT}}- **Fork PRs:** {{FORK_COUNT}} (marked in tables — no automated agent review, require manual review){{/if}}
<!-- review-queue-bot -->
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal-workflows/pr-overview/templates/review-queue.md` around lines 66 -
73, Insert the hidden HTML marker <!-- review-queue-bot --> into the
review-queue template so generated reports are identifiable by the workflow; add
this marker as a standalone HTML comment at the top (or bottom) of the template
content (outside the Markdown headings) while leaving the existing variables
like {{READY_COUNT}}, {{MILESTONE_COUNT}}, {{NEAR_COUNT}}, {{WORK_COUNT}},
{{CLOSE_COUNT}}, and optional {{FORK_COUNT}} unchanged.

- Fix ambient.json: remove stale "test merge order" ref, update to 9-step
- Fix CLAUDE.md: UNKNOWN mergeability is warn, not blocker (matches script)
- Fix analyze-prs.py: check_reviews returns FAIL when fetch_ok=False
- Fix analyze-prs.py: recompute fail_count after overlap_status is set
- Fix fetch-pr.sh: use headRefOid instead of statusCheckRollup for HEAD SHA
- Fix rubric.md: benchmark step order matches actual workflow
- Fix markdown: add language specs to fenced code blocks in READMEs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Gkrumbach07
Gkrumbach07 merged commit dc7a0a7 into main Mar 10, 2026
Gkrumbach07 added a commit to ambient-code/platform that referenced this pull request Mar 10, 2026
## Summary

- **Review Queue** (`pr-merge-review.yml`): renamed from "PR Merge
Review", updated prompt for type classification and sub-agent
evaluation, removed unused `SESSION_RESULT` env var
- **PR Fixer** (`pr-fixer.yml`): new workflow with 4 triggers:
  - `agent-managed` label added to a PR (immediate)
  - `@ambient-fix` comment from collaborator/member/owner (immediate)
- Schedule: every 4 hours weekdays for all `agent-managed` PRs with
recent activity
  - Manual: `workflow_dispatch` with PR number

### How they work
- Review Queue runs daily, creates an Ambient session that evaluates all
open PRs and generates a prioritized queue
- PR Fixer fires off Ambient sessions to fix individual PRs (rebase,
address feedback, lint, test, push)
- Batch scheduled job finds `agent-managed` PRs updated in last 4h,
spawns parallel sessions (fire-and-forget)

### Dependencies
- Requires
[ambient-code/workflows#63](ambient-code/workflows#63)
to be merged first (the workflow definitions these actions point to)

## Test plan
- [ ] Manually trigger Review Queue via workflow_dispatch
- [ ] Add `agent-managed` label to a test PR and verify PR Fixer
triggers
- [ ] Comment `@ambient-fix` on a PR and verify it triggers
- [ ] Verify batch schedule finds agent-managed PRs correctly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant